package cn.it.controller;

import cn.it.Service.IGoodsService;
import cn.it.domain.Goods;
import cn.it.util.MyException;
import cn.it.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    IGoodsService iGoodsService;
    @RequestMapping("/queryGoodsByType")
    public Object queryGoodsByType(Integer typeid){
        System.out.println("----"+typeid);
        HashMap<String, Object> map = new HashMap<>();
        List<Goods> goods = null;
        try {
            goods = iGoodsService.queryGoodsByType(typeid);
            map.put("code",200);
            map.put("msg","查询成功");
            map.put("data",goods);
        } catch (MyException e) {
            map.put("code",201);
            map.put("msg",e.getMessage());
            map.put("data",null);

        }
        return map;
    }
    @RequestMapping("/queryGoodsById")
    public Object queryGoodsById(Integer id){
         iGoodsService.queryGoodsByID(id);
        Result result = iGoodsService.queryGoodsByID(id);
            return result;
    }
}
